<?php
namespace app\common\model;

use think\Model;

class ShouyePartner extends Model
{
	protected $insert = ['create_time'];

    /**
     * 创建时间
     * @return bool|string
     */
    protected function setCreateTimeAttr()
    {
        return date('Y-m-d H:i:s');
    }

    /**
     * 获得合作伙伴
     * @return int
     */
    public function getpartnerlist($keyword,$page)
    {
    	$map = [];
    	if (!empty($keyword)) {
            $map['name'] = ['like', "%{$keyword}%"];
        }
    	$partnerlist = $this->where($map)->order(['create_time' => 'DESC'])->paginate(10, false, ['page' => $page]);
    	return $partnerlist;
    }

    /**
     * 更改合作伙伴显示的状态
     * @return int
     */
    public function change($id)
    {
    	$status = $this->where('id',$id)->column('status');
    	$status[0] ? $status1 = 0 : $status1 = 1;
    	$list = $this->allowField(true)->save(['status'=>$status1],['id'=>$id]);
    	return $list;
    }

}